package com.ellfors.module_first.edge_effect

import android.content.Intent
import android.os.Handler
import android.os.Looper
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.ellfors.common.base.BaseActivity
import com.ellfors.common.base.EmptyViewModel
import com.ellfors.module_first.databinding.ActivityEdgeEffectBinding

/**
 * @date: 2024/07/03
 * @author: ly
 * @Description: 带阻尼效果的RecyclerView
 */
class EdgeEffectActivity : BaseActivity<ActivityEdgeEffectBinding, EmptyViewModel>() {

    private val mAdapter by lazy {
        EdgeEffectAdapter()
    }

    private val leakHandler = Handler(Looper.getMainLooper())

    companion object {
        fun start(activity: AppCompatActivity) {
            Intent(activity, EdgeEffectActivity::class.java).apply {
                activity.startActivity(this)
            }
        }
    }

    override fun initView() {
        mBinding.recyclerView.layoutManager = LinearLayoutManager(this)
        mBinding.recyclerView.adapter = mAdapter
    }

    override fun initData() {
        val list = arrayListOf<String>()
        for (i in 0 until 30) {
            list.add("item $i")
        }
        mAdapter.submitList(list)

        leakHandler.postDelayed({
            Toast.makeText(this, "Memory leak simulated", Toast.LENGTH_LONG).show()
        }, 5000) // 5 秒后执行
    }
}